<template>
	<view>
		<cu-custom :bgcolor="'#fff'"/>	
		<view class="p-2">
			<uni-forms :modelValue="formData" label-position="top"  ref="form">
				<uni-forms-item label="经度" name="name">
					<uni-easyinput type="text" v-model="formData.jingdu" placeholder="请输入经度" />
				</uni-forms-item>
				<uni-forms-item label="纬度" name="name">
					<uni-easyinput type="text" v-model="formData.weidu" placeholder="请输入纬度" />
				</uni-forms-item>
				<button class="main-bg-color text-white font-md mt-4 mb-4" @click="getUserLocaton">打开地图获取</button>
				<button class="main-bg-color text-white font-md mb-4" @click="submit">确认</button>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	import cuCustom from '@/components/common/custom.vue'
	import interceptor from "@/utils/request.js"
	export default {
		components: {
			cuCustom
		},
		data() {
			return {
				title: 'map',
				scale: 16,
				formData:{
					jingdu:"",
					weidu:""
				}
			}
		},
		onShow() {
			this.getLL()
		},
		methods: {
			getUserLocaton(){
				let _that = this
				uni.chooseLocation({
					success: (res) => {
						console.log(res)
						_that.formData.jingdu = res.longitude
						_that.formData.weidu = res.latitude
					}
				})
			},
			submit(){
				let params = Object.assign({},{supplier_id: uni.getStorageSync("supplier_id")},this.formData)
				interceptor.get("/supplier_applet_api.php?act=setLong",params).then((res) =>{
					if (res.status === 1) {
						uni.showToast({
							title: res.msg,
							icon: "success",
							success() {
								uni.navigateBack()
							}
						})
						
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			getLL(){
				interceptor.get("/supplier_applet_api.php?act=setLong",{supplier_id: uni.getStorageSync("supplier_id")}).then((res) =>{
					this.formData.jingdu = this.formData.jingdu == ''? res.info.supplier.longitude : this.formData.jingdu
					this.formData.weidu = this.formData.weidu =='' ? res.info.supplier.latitude : this.formData.weidu
					this.$forceUpdate()
				})
			}

		}
	}
</script>

<style>

</style>